package com.jss.lanouhn.fristapp.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.jss.lanouhn.fristapp.R;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.tencent.qq.QQ;

public class LoginActivity extends AppCompatActivity {

    private ImageView iv_sina,iv_wechat,iv_qq;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        initView();
        initEvent();
        
    }



    private void initView() {
        iv_sina= (ImageView) findViewById(R.id.iv_login_sina);
        iv_wechat= (ImageView) findViewById(R.id.iv_login_wechat);
        iv_qq= (ImageView) findViewById(R.id.iv_login_qq);

    }

    private void initEvent() {
        iv_qq.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ShareSDK.initSDK(LoginActivity.this);
                Platform qq = ShareSDK.getPlatform(QQ.NAME);
                qq.setPlatformActionListener(new PlatFromLis());
//                qq.authorize();//单独授权
                qq.showUser(null);//授权并获取用户信息
               //authorize与showUser单独调用一个即可
               //移除授权
               //weibo.removeAccount(true);
            }
        });
    }

    private class PlatFromLis implements PlatformActionListener {
        @Override
        public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
            Iterator ite = hashMap.entrySet().iterator();
            while (ite.hasNext()) {
                Map.Entry entry = (Map.Entry) ite.next();
                Object key = entry.getKey();
                Object value = entry.getValue();
                System.out.println(key + "： " + value);
            }

            Intent intent = new Intent(LoginActivity.this,MainActivity.class);
            startActivity(intent);


        }

        @Override
        public void onError(Platform platform, int i, Throwable throwable) {
            Log.i("result", "onError");
            Intent intent = new Intent(LoginActivity.this,MainActivity.class);
            startActivity(intent);

        }

        @Override
        public void onCancel(Platform platform, int i) {
            Log.i("result", "onCancel");
        }
    }
}
